#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> 
#include<bits/stdc++.h>
using namespace std;

const int N = 1010;

char ser[N][30];
int cnt[N];
int p = 0;

bool check(char da[]){
	int n = 0;
	int nd = 0, nm = 0;
	bool u = false;
	int dap = 0;
	while(da[dap] != '\0'){
		n++;
		if(da[dap] == '.') nd++;
		if(nd == 3) u = true;
		if(da[dap] == ':') nm++;
		if(u == false && nm > 0) return false;
		dap++;
	}
	if(nd != 3 || nm != 1) return false;
	int num = 0;
	bool f = false;
	for(int i = 0; i < n; i++){
		if(da[i] >= '0' && da[i] <= '9'){
			num = num*10+da[i]-'0';
		}
		else if(f == true){
			if(num > 65536) return false;
		}
		else{
			if(num > 255) return false;
			num = 0;
			if(da[i] == ':') f = true;
		}
		if(i > 0 && da[i] == '0' && !(da[i-1] >= '0' && da[i-1] <= '9') && (da[i+1] >= '0' && da[i+1] <= 9)) return false;
		else if(i == 0 && da[i] == '0' && (da[i+1] >= '0' && da[i+1] <= 9)) return false;
	}
	return true;
}

int main(){
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		char typ[7];
		cin >> typ;
		if(typ[0] == 'S'){
			char de[30];
			cin >> de;
			int nde = 0;
			while(de[nde] != '\0'){
				nde++;
			}
			bool flag = check(de);
			if(flag){
				bool sames = true;
				for(int i = 1; i <= p; i++){
					int ns = 0;
					while(ser[i][ns] != '/0') ns++;
					if(ns == nde){
						for(int v = 0; v < nde; v++){
							if(ser[i][v] != de[v]){
								sames = false;
								break;
							}
						}
					}
					if(sames == false) break;
				}
				if(sames == false){
					p++;
				int tp = 0;
				while(de[tp] != '\0'){
					ser[p][tp] = de[tp];
					tp++;
				}
				ser[p][tp] = '\0';
			    cnt[p] = 0;
			    cout << "OK" << endl;
				}
				else cout << "FAIL";
			}
			else{
				cout << "ERR" << endl;
			}
		}
		else{
			char de[30];
			cin >> de;
			int f = check(de);
			if(f == false) cout << "ERR" << endl;
			
			for(int i = 1; i <= p; i++){
				bool sames = true;
				int ns = 0;
				while(ser[i][ns] != '/0') ns++;
				if(ns == nde){
					for(int v = 0; v < nde; v++){
						if(ser[i][v] != de[v]){
							sames = false;
							break;
						}
					}
				}
				if(sames == true){
					cnt[i]++;
					cout << cnt[i] << endl;
					break;
				} 
			}
			if(sames == false) cout << "FAIL" << endl;
		}
	}
	return 0;
}
